﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/assets/libs/layui/css/layui.css" />
    <link rel="stylesheet" href="/assets/module/admin.css?v=318">
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        .layui-layer.layui-layer-adminRight {
            bottom: 0;
            top: 0 !important;
            border: none !important;
            box-shadow: 1px 1px 50px rgba(0, 0, 0, .3) !important;
            overflow: auto;
        }
        .layui-table-view .layui-table td {
            cursor: pointer
        }
    </style>
</head>
<body>
    <!-- 主体部分 -->
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-card-body">
                <!-- 表格工具栏 -->
                <form class="layui-form toolbar">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">字典描述:</label>
                            <div class="layui-input-inline">
                                <input name="Remark" class="layui-input" placeholder="" />
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">字典类型:</label>
                            <div class="layui-input-inline">
                                <input name="DictType" class="layui-input" placeholder="" />
                            </div>
                        </div>
                        <div class="layui-inline">
                            &emsp;
                            <button class="layui-btn icon-btn" lay-filter="TbSearch" lay-submit perm-show="system:datadict:search">
                                <i class="layui-icon">&#xe615;</i>搜索
                            </button>
                        </div>
                    </div>
                </form>
                <!-- 数据表格 -->
                <table id="gridTable" lay-filter="gridTable"></table>
            </div>
        </div>
    </div>
    <!-- 表格头工具栏 -->
    <script type="text/html" id="toolbar">
        <a perm-show="system:datadict:add" class="layui-btn layui-btn-sm icon-btn" lay-event="add"><i class="layui-icon">&#xe654;</i>新增</a>
        <a perm-show="system:datadict:edit" class="layui-btn layui-btn-warm layui-btn-sm icon-btn" lay-event="edit"><i class="layui-icon">&#xe642;</i>修改</a>
        <a perm-show="system:datadict:delete" class="layui-btn layui-btn-danger layui-btn-sm icon-btn" lay-event="del"><i class="layui-icon">&#xe640;</i>删除</a>
    </script>
    <!-- 表格头工具栏 -->
    <script type="text/html" id="toolbar">
        <a perm-show="system:datadictdetail:add" class="layui-btn layui-btn-sm icon-btn" lay-event="add"><i class="layui-icon">&#xe654;</i>新增</a>
        <a perm-show="system:datadictdetail:edit" class="layui-btn layui-btn-warm layui-btn-sm icon-btn" lay-event="edit"><i class="layui-icon">&#xe642;</i>修改</a>
        <a perm-show="system:datadictdetail:delete" class="layui-btn layui-btn-danger layui-btn-sm icon-btn" lay-event="del"><i class="layui-icon">&#xe640;</i>删除</a>
    </script>

    <!-- js部分 -->
    <script src="/assets/libs/jquery/jquery-3.2.1.min.js"></script>
    <script src="/assets/libs/layui/layui.js"></script>
    <script src="/assets/js/main.js"></script>
    <script src="/assets/js/utils.js"></script>
    <script>

        // 全局变量
        var table;
        var checkId;
        var tempClickFlag;

        layui.use(['layer', 'form', 'table', 'util', 'admin', 'setter', 'tableX'], function () {
            var layer = layui.layer;
            var form = layui.form;
            table = layui.table;
            var util = layui.util;
            var admin = layui.admin;
            var setter = layui.setter;
            var tableX = layui.tableX;

            // 表格初始化
            layuiTableSet();

            /* 渲染表格 */
            var insTb = table.render({
                elem: '#gridTable',
                url: setter.baseServer + '/SystemManage/DataDict/GetPageListJson',
                page: true,
                toolbar: "#toolbar",
                cols: [[
                    { type: 'checkbox' },
                    { type: 'numbers' },
                    { field: 'Remark', title: '字典描述', width: 300 },
                    { field: 'DictType', title: '字典类型' },
                    {
                        field: 'CreateTime', title: '创建时间', templet: function (d) {
                            return util.toDateString(d.CreateTime);
                        }
                    },
                ]],
                done: function () {
                    // 校验权限
                    CheckButtonAuthority();
                    $('div[lay-id="gridTable"] td[data-field="0"]').click(function (e) {
                        // 此处不能阻断方法，否则无法获取选中行，所以加个标识，阻止下面的行单击事件继续运行
                        tempClickFlag = true;
                    });
                }
            });

            //监听行单击事件
            table.on('row(gridTable)', function (obj) {
                // 见表格done回调
                if (tempClickFlag) { tempClickFlag = false; return; }

                checkId = obj.data.DictType;
                var option = admin.util.deepClone($(this).data());
                admin.strToWin(option.window).layui.admin.popupRight($.extend({
                    id: 'layer-theme',
                    // 加ID 防范缓存
                    url: 'datadictdetailIndex.html?Id=' + checkId,
                    area: '1000px'
                }, admin.parseLayerOption(option)));
            });

            /* 表格搜索 */
            form.on('submit(TbSearch)', function (data) {
                insTb.reload({ where: data.field, page: { curr: 1 } });
                return false;
            });

            /* 表格头工具栏点击事件 */
            table.on('toolbar(gridTable)', function (obj) {
                if (obj.event === 'add') {
                    // 添加
                    showEditModel();
                } else if (obj.event === 'edit') {
                    // 修改
                    var checkRows = table.checkStatus('gridTable');
                    if (checkRows.data.length === 0 || checkRows.data.length > 1) {
                        layer.msg('请选择且只选择一条数据', { icon: 2 });
                        return;
                    }
                    showEditModel(checkRows.data[0]);
                } else if (obj.event === 'del') {
                    // 删除
                    var checkRows = table.checkStatus('gridTable');
                    if (checkRows.data.length === 0) {
                        layer.msg('请选择要删除的数据', { icon: 2 });
                        return;
                    }
                    var ids = checkRows.data.map(function (d) {
                        return d.Id;
                    });
                    doDel({ ids: ids });
                } else if (obj.event == 'export') {
                    // 导出
                    var cols = [[
                        { field: 'Remark', title: '字典描述', width: 300 },
                        { field: 'DictType', title: '字典类型' },
                        {
                            field: 'CreateTime', title: '创建时间', templet: function (d) {
                                return util.toDateString(d.CreateTime);
                            }
                        },
                    ]];
                    layuiTableExport(cols, setter.baseServer + '/SystemManage/DataDict/GetListJson', '数据字典导出')
                }
            });

            /* 显示表单弹窗 */
            function showEditModel(mData) {
                var id = 0;
                if (mData != undefined && mData != null) { id = mData.Id; }
                admin.open({
                    type: 2,
                    area: ['500px', '360px'],
                    title: (mData ? '修改' : '添加'),
                    content: 'DataDictForm.html?id=' + id,
                });
            }

            /* 删除 */
            function doDel(obj) {
                layer.confirm('确定要删除选中数据吗？', {
                    skin: 'layui-layer-admin',
                    shade: .1
                }, function (i) {
                    layer.close(i);
                    var loadIndex = layer.load(2);
                    admin.req('/SystemManage/DataDict/DeleteFormJson', obj.ids.join(','), function (res) {
                        layer.close(loadIndex);
                        if (1 === res.Tag) {
                            layer.msg("操作成功", { icon: 1 });
                            insTb.reload({ page: { curr: 1 } });
                        } else {
                            layer.msg(res.Message, { icon: 2 });
                        }
                    }, 'post');
                });
            }
        });
    </script>
</body>
</html>